/** CFD Solver For Box Flow
 * simple method
 **/
#include <iostream>
#include <vector>
#include <fstream>
using namespace std;

class Spacial_Gener //< Basis
{
public:
    virtual void GenerateGrid() = 0; //< 网格定义
    virtual void Init() = 0;         //< 初场
    virtual void Reconstruct() = 0;  //< 重构
    virtual void GetFlux() = 0;      //< 通量
    virtual ~Spacial_Gener()         //< delete
    {
        cout << "<<       Computation Finish!       >>" << endl;
    }

public:
    int ncells_;
};

typedef class Spacial_Dis : virtual public Spacial_Gener //< 空间离散
{
public:
    Spacial_Dis(int ncells, double xs, double xe, double ys, double ye)
        : xs_(xs), xe_(xe), ys_(ys), ye_(ye),
          x_(new double[(ncells + 1) * (ncells + 1)]),
          y_(new double[(ncells + 1) * (ncells + 1)]),
          xc_(new double[(ncells) * (ncells)]), //< 1-D store
          yc_(new double[(ncells) * (ncells)])
    {
        ncells_ = ncells; //< 一条网格的单元数
    }

    void GenerateGrid()
    {
        /*ofstream file1;
        file1.open("gird.plt");
        file1 << "variables = \"x\", \"y\"" << endl;
        file1 << "ZONE DATAPACKING = POINT, "
              << "I = " << ncells_ + 1 << ' ' << "J = " << ncells_ + 1 << endl;*/
        for (int i = 0; i < (ncells_ + 1); i++) //< i代表行
        {
            for (int j = 0; j < (ncells_ + 1); j++) //< j代表列
            {
                x_[j + (ncells_ + 1) * i] = xs_ + j * (xe_ - xs_) / ncells_;
                y_[j + (ncells_ + 1) * i] = ys_ + i * (ye_ - ys_) / ncells_; //< 一维存贮的索引方式
                //file1 << x_[j + (ncells_ + 1) * i] << '\t' << y_[j + (ncells_ + 1) * i] << endl;
            }
        }
    }

    void Reconstruct()
    {
    }

    void GetFlux()
    {
    }

    void Init()
    {
    }

public:
    double xs_, xe_, ys_, ye_;
    double *x_, *y_, *xc_, *yc_;
} spa;

class FactorySolver //< 组装
{
public:
    FactorySolver(int ncells, double xs, double xe, double ys, double ye)
        : xs_(xs), xe_(xe), ys_(ys), ye_(ye), ncells_(ncells)
    {
        cout << "<<       Computation Start!       >>" << endl;
    }

    spa *CreatSolver()
    {
        return new spa(ncells_, xs_, xe_, ys_, ye_);
    }

public:
    double xs_, xe_, ys_, ye_;
    int ncells_;
};
